﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Zvezda.FSO2.DB;

namespace FSO.Reports
{
    public partial class UserControlContractSelector : UserControl
    {
        public UserControlContractSelector()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Флаг нулевого значения
        /// </summary>
        public bool IsNull
        {
            get
            {
                bool bReturn = true;
                if (radCheckBoxContractIsNull.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On
                    && _SelectedContract != null)
                {
                    bReturn = false;
                }
                 return bReturn;
            }
        }
        /// <summary>
        /// Обрабатывает изменения состояния переключателя выбора значения
        /// </summary>
        private void radCheckBoxOrgIsNull_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
        {
            if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
            {
                radButtonSelectContract.Enabled = true;
                radLabelContractNumber.BackColor = Color.White;
                radLabelContractNumber.Cursor = Cursors.Hand;
            }
            else
            {
                radButtonSelectContract.Enabled = false;
                radLabelContractNumber.BackColor = Color.WhiteSmoke;
                radLabelContractNumber.Cursor = Cursors.Default;
            }
        }

        private DataSetFSO.CONTRACTRow _SelectedContract = null;
        /// <summary>
        /// Строка выбранного договора
        /// </summary>
        public DataSetFSO.CONTRACTRow SelectedRow
        {
            get
            {
                return _SelectedContract;
            }
        }

        private void radButtonSelectContract_Click(object sender, EventArgs e)
        {
            if (radCheckBoxContractIsNull.ToggleState != Telerik.WinControls.Enumerations.ToggleState.On)
            {
                return;
            }
            DialogFormSelectObject dlgFrmSelectObject = new DialogFormSelectObject(ObjctTypeEnum.CONTRACT);
            if (dlgFrmSelectObject.ShowDialog() == DialogResult.OK)
            {
                _SelectedContract = dlgFrmSelectObject.SelectedRow as DataSetFSO.CONTRACTRow;
                radLabelContractNumber.Text = _SelectedContract.NUMBER;
            }
        }
    }
}
